﻿<%@ Page Language="C#" MasterPageFile="~/webui/admin/adminTemplate.master" AutoEventWireup="true"
    CodeFile="admin_member.aspx.cs" Inherits="admin_member" Title=".::E-Valuation System::.." %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div class="UIDivInfo">
        <div class="UITabPane" style="margin-top: 15px;">
            <div class="TabPaneContent">
                <div class="WorkingAreaWithHelp" style="width: 98.5%;">
                    <div class="UIHorizontalTabs">
                        <div class="LeftHorizontalTabs">
                            <div class="RightHorizontalTabs">
                                <div class="CenterHorizontalTabs">
                                    <div class="TabsContainer">
                                        <asp:PlaceHolder ID="TabsContainer" runat="server">
                                            <div class="UITab NormalTabStyle">
                                                <% String className = "NormalTab";
                                                   if (getSelectedTab().Equals("0"))
                                                   {
                                                       className = "SelectedTab";
                                                   }
                                                %>
                                                <div id="UITab0" class="<%=className %>">
                                                    <div class="LeftTab">
                                                        <div class="RightTab">
                                                            <div class="MiddleTab">
                                                                <asp:LinkButton CssClass="NormalLink" ID="TabValue0" runat="server" CausesValidation="false"
                                                                    OnClick="ChangeTabIndex">
                                                                  Danh sách  tài khoản
                                                                </asp:LinkButton>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="UITab NormalTabStyle">
                                                <%
                                                    className = "NormalTab";
                                                    if (getSelectedTab().Equals("1"))
                                                    {
                                                        className = "SelectedTab";
                                                    }
                                                %>
                                                <div id="UITab1" class="<%=className %>">
                                                    <div class="LeftTab">
                                                        <div class="RightTab">
                                                            <div class="MiddleTab">
                                                                <asp:LinkButton CssClass="NormalLink" ID="TabValue1" runat="server" CausesValidation="false"
                                                                    OnClick="ChangeTabIndex">
                                                                 Tạo mới tài khoản
                                                                </asp:LinkButton>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </asp:PlaceHolder>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div style="clear: left;">
                        <span></span>
                    </div>
                    <asp:PlaceHolder ID="UITabContentContainer" runat="server">
                        <div class="UITabContentContainer">
                            <%
                                String styleDisplay = "none";
                                if (getSelectedTab().Equals("0"))
                                {
                                    styleDisplay = "block";
                                }
                            %>
                            <div id="UITabContent0" class="UITabContent" style="display: <%=styleDisplay %>">
                                <asp:Panel ID="Panel0" runat="server">
                                    <div  style="overflow:scroll;" >
                                        <asp:GridView ID="grvMemLst" DataSourceID="dsMemLst" runat="server" AllowPaging="True"
                                            AutoGenerateColumns="False" DataKeyNames="id" PageSize="10" CssClass="Grv" OnRowCommand="grvMemLst_RowCommand"
                                            OnRowDataBound="grvMemLst_RowDataBound">
                                            <Columns>
                                                <asp:BoundField DataField="id" HeaderText="MaNguoiDung" InsertVisible="False" ReadOnly="True" />
                                                <asp:BoundField DataField="TenTruyCap" HeaderText="Tên truy cập" />
                                                <asp:BoundField DataField="MatKhau"  HeaderText="Mật khẩu" />
                                                <asp:BoundField DataField="rightID" HeaderText="rightID" />
                                                <asp:BoundField DataField="shortDec" HeaderText="Quyền" />
                                                <asp:BoundField DataField="MaDoanhNghiep" HeaderText="MaDoanhNghiep" />
                                                <asp:BoundField DataField="TenDoanhNghiep" HeaderText="Tên Doanh nghiệp" />
                                                <asp:TemplateField HeaderText="Chức năng">
                                                    <ItemTemplate>
                                                        <asp:ImageButton ID="sua" CommandArgument='<%# Eval("TenTruyCap") %>' CommandName="Sua"
                                                            runat="server" ImageUrl="~/App_Themes/Default/Css/images/edit.gif" CausesValidation="false"
                                                            AlternateText="Sửa thông tin Người dùng" />
                                                        <asp:ImageButton ID="xoa" CommandArgument='<%# Eval("TenTruyCap") %>' CommandName="Xoa"
                                                            runat="server" ImageUrl="~/App_Themes/Default/Css/images/delete.gif" CausesValidation="false"
                                                            AlternateText="Xóa Người dùng" />
                                                    </ItemTemplate>
                                                    <ItemStyle HorizontalAlign="Center" />
                                                </asp:TemplateField>
                                            </Columns>
                                            <PagerStyle CssClass="GrvPagerStyle" />
                                            <HeaderStyle CssClass="GrvHeader" />
                                            <RowStyle CssClass="GrvRowStyle" />
                                            <AlternatingRowStyle CssClass="GrvAlternatingRowStyle" />
                                        </asp:GridView>
                                    </div>
                                </asp:Panel>
                            </div>
                            <%
                                styleDisplay = "none";
                                if (getSelectedTab().Equals("1"))
                                {
                                    styleDisplay = "block";
                                }
                            %>
                            <div id="UITabContent1" class="UITabContent" style="display: <%=styleDisplay %>">
                                <asp:Panel runat="server" ID="CapPhepPanle" CssClass="UITabContentReg">
                                    <div  >
                                        <div class="MemberForm">
                                            <div class="Field">
                                                <label>
                                                    ID</label>
                                                <asp:TextBox ID="id" runat="server" CssClass="Textbox" ReadOnly="true"></asp:TextBox>
                                            </div>
                                            <div class="Field">
                                                <label>
                                                    Tên đăng nhập</label>
                                                <asp:TextBox ID="mem_id" runat="server" CssClass="Textbox"></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="mem_id"
                                                    ErrorMessage="Không được trống" CssClass="ValidateLabel" Display="Dynamic"></asp:RequiredFieldValidator>
                                            </div>
                                            <div class="Field">
                                                <label>
                                                    Mật khẩu</label>
                                                <asp:TextBox TextMode="Password" ID="mem_pass" runat="server" CssClass="Textbox"></asp:TextBox>
                                                <asp:RequiredFieldValidator ID="rfvPass" runat="server" ControlToValidate="mem_pass"
                                                    ErrorMessage="Không được trống" CssClass="ValidateLabel" Display="Dynamic"></asp:RequiredFieldValidator>
                                            </div>
                                            <div class="Field">
                                                <label>
                                                    Quyền</label>
                                                <asp:DropDownList ID="cb_pripority" runat="server" CssClass="DropdownList" DataSourceID="cb_quyenDataView"
                                                    DataTextField="shortDec" DataValueField="rightID" AutoPostBack="True" OnSelectedIndexChanged="cb_pripority_SelectedIndexChanged">
                                                </asp:DropDownList>
                                            </div>
                                            <div class="Field">
                                                <label>
                                                    Thuộc doanh nghiệp</label>
                                                <asp:DropDownList ID="cb_doanhnghiep" runat="server" CssClass="DropdownList" DataSourceID="doanhnghiepData"
                                                    DataTextField="tendoanhnghiep" DataValueField="madoanhnghiep">
                                                </asp:DropDownList>
                                                <div class="ClearAll">
                                                    <span></span>
                                                </div>
                                            </div>
                                            <div class="Field">
                                                <label>
                                                    Người được cấp</label>
                                                <asp:DropDownList ID="cb_memberSelectData" OnSelectedIndexChanged="cb_memberSelectData_SelectedIndexChanged"
                                                    runat="server" CssClass="DropdownList" DataSourceID="memberSelectData" DataTextField="Hovaten"
                                                    DataValueField="idguest">
                                                </asp:DropDownList>
                                                <label>
                                                    Gửi thư thông báo
                                                </label>
                                                <asp:CheckBox CssClass="Checkbox" ID="is_sendmail" runat="server" />
                                            </div>
                                            <div class="Field" style="text-align: center">
                                                <asp:Button ID="btn_Save" Text="Ghi lại" runat="server" OnClick="btn_Save_Click"
                                                    CssClass="Button" />
                                                &nbsp;
                                                <asp:Button ID="btn_Reset" Text="Làm lại" runat="server" OnClick="btn_Reset_Click"
                                                    CausesValidation="False" CssClass="Button" />
                                            </div>
                                        </div>
                                    </div>
                                </asp:Panel>
                            </div>
                        </div>
                    </asp:PlaceHolder>
                </div>
            </div>
        </div>
    </div>
  <div>
    <asp:SqlDataSource ID="cb_quyenDataView" runat="server" ConnectionString="<%$ ConnectionStrings:evaConn%>"
        SelectCommand="SELECT [rightID], [shortDec] FROM [rights]  "></asp:SqlDataSource>
    <asp:SqlDataSource ID="doanhnghiepData" runat="server" ConnectionString="<%$ ConnectionStrings:evaConn %>"
        SelectCommand="SELECT MaDoanhNghiep, TenDoanhNghiep FROM DoanhNghiep WHERE (Status = 1) UNION SELECT '0' AS MaDoanhNghiep, N'Không thuộc Doanh nghiệp' AS TenDoanhNghiep">
   
    </asp:SqlDataSource>
    <asp:HiddenField ID="mem_hiddenId" runat="server" />
    <asp:SqlDataSource ID="memberSelectData" runat="server" ConnectionString="<%$ ConnectionStrings:evaConn %>"
        SelectCommand="SELECT idguest, Hovaten FROM guest  WHERE Tentruycap is null or (Tentruycap NOT IN (SELECT Tentruycap FROM Users)) UNION SELECT '0' AS  idguest , N'Danh sách người dùng'">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsMemLst" runat="server" ConnectionString="<%$ ConnectionStrings:evaConn %>"
        SelectCommand="SELECT Users.[id], Users.Tentruycap, Users.Matkhau,rights.rightID, rights.shortDec, Users.MaDoanhNghiep, DoanhNghiep.TenDoanhNghiep FROM Users INNER JOIN rights ON rights.rightID = Users.Quyen INNER JOIN (SELECT MaDoanhNghiep, TenDoanhNghiep FROM DoanhNghiep UNION SELECT '0',N'Hệ thống') DoanhNghiep ON DoanhNghiep.MaDoanhNghiep = Users.MaDoanhNghiep ORDER BY Users.[TenTruyCap]"
        UpdateCommand="UPDATE guest SET Tentruycap = N'' WHERE TenTruyCap = @TenTruyCap; DELETE FROM Users WHERE TenTruyCap = @TenTruyCap">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsUserEdit" runat="server" ConnectionString="<%$ ConnectionStrings:evaConn %>"
        InsertCommand="INSERT INTO Users(Tentruycap, MatKhau, Quyen, MaDoanhNghiep) VALUES (@TenTruyCap, @MatKhau, @Quyen, @MaDoanhNghiep)">
        <InsertParameters>
            <asp:ControlParameter ControlID="mem_id" Name="TenTruyCap" PropertyName="Text" />
            <asp:ControlParameter ControlID="mem_pass" Name="MatKhau" PropertyName="Text" />
            <asp:ControlParameter ControlID="cb_pripority" Name="Quyen" PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="cb_doanhnghiep" Name="MaDoanhNghiep" PropertyName="SelectedValue" />
        </InsertParameters>
    </asp:SqlDataSource>
    </div>
</asp:Content>
